// ArtCtrl.cpp : Implementation of DLL Exports.

#include "stdafx.h"
#include "resource.h"
#include "ArtCtrl.h"
#include "ArtCtrl_i.c"
#include "ArtFrame_i.c"
#include "ArtFrameImpl.h"

//IArtApp *gApp = NULL;
class CArtCtrlModule : public CAtlDllModuleT< CArtCtrlModule >
{
public :

//	CComPtr<IArtApp> *m_pApp;
	DECLARE_LIBID(LIBID_ArtCtrlLib)
	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_ARTCTRL, "{3CE507E9-68B5-4245-AECE-62E713662443}")
	//void LoadArtApp()
	//{
	//	GETARTAPP	GetArtApp	= NULL;
	//	HINSTANCE	hInst		= NULL;
	//	CPath		path;
	//	GetModuleFileName(_AtlBaseModule.GetModuleInstance(), path.m_strPath.GetBuffer(MAX_PATH), MAX_PATH);
	//	path.RemoveFileSpec();
	//	path.AddBackslash();
	//	path.Append(_T("ArtFrame.dll"));

	//	if (path.FileExists())
	//	{
	//		//::MessageBox(0, _T(""), _T(""), MB_OK);
	//		hInst = GetModuleHandle(path.m_strPath);
	//		if (hInst != NULL)
	//		{
	//			GetArtApp = (GETARTAPP)GetProcAddress(hInst, "GetArtApp");
	//			GetArtApp((IArtApp**)&gApp);
	//		}
	//	}
	//}

	//void FreeArtApp()
	//{
	//	if (NULL != gApp)
	//	{
	//		gApp->Release();
	//		gApp = NULL;
	//	}
	//	TraceDebug(_T("%s, aaaaaaaaaaaa"), _T("asfd"));
	//}
};

CArtCtrlModule _AtlModule;


// DLL Entry Point
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	hInstance;
	if (DLL_PROCESS_ATTACH == dwReason)
	{
		//HINSTANCE hInst = LoadLanguageFile((LPCTSTR)hInstance, llfInstFrame);
		//if (NULL != hInst)
		//	ATL::_AtlBaseModule.SetResourceInstance(hInst);
		//_AtlModule.LoadArtApp();
		InitCommonControls();  
	}else if(DLL_PROCESS_DETACH == dwReason)
	{
		//_AtlModule.FreeArtApp();
	}
    return _AtlModule.DllMain(dwReason, lpReserved); 
}


// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
    return _AtlModule.DllCanUnloadNow();
}


// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
    return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}


// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
    // registers object, typelib and all interfaces in typelib
    HRESULT hr = _AtlModule.DllRegisterServer();
	return hr;
}


// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
	HRESULT hr = _AtlModule.DllUnregisterServer();
	return hr;
}
